﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace Geldtransporter
{
    class ReadFile
    {

        private List<string> input = new List<string>();
        public ReadFile(string path)
        {
            try
            {

                string readIn;
                StreamReader reader = new StreamReader(path);

                while ((readIn = reader.ReadLine()) != null)
                {
                    input.Add(readIn);
                }

            }
            catch (Exception)
            {
                global::System.Windows.MessageBox.Show("File could not be read");;
            }
        }

        public BagStack GetKofferList()
        {
            BagStack ret = new BagStack();

            foreach (var item in input)
            {
                if (!(input.IndexOf(item) == 0))
                {
                    int money;
                    int weight;
                    string[] splitted = item.Split(' ');
                    Int32.TryParse(splitted[0], out money);
                    Int32.TryParse(splitted[1], out weight);

                    ret.Add(new MoneyBag(money, weight));
                }
            }

            return ret;
        }

    }
}
